package com.hyb.exceion;

import com.hyb.response.Result;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authc.ExpiredCredentialsException;
import org.apache.shiro.authz.UnauthenticatedException;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
/**
 * <p>
 * 异常
 * </p>
 *
 * @author hyb
 * @since 2021-12-29
 */
@RestControllerAdvice
@Slf4j
public class GlobalException {

    @ExceptionHandler(value = UnauthorizedException.class)
    public Result handler(UnauthorizedException e){
        log.error("运行时异常----------------"+e.getMessage());
        return new Result().setCode(401).setMessage("无权限访问");
    }
    @ExceptionHandler(value = ExpiredCredentialsException.class)
    public Result handler(ExpiredCredentialsException e){
        log.error("运行时异常----------------"+e.getMessage());
        return new Result().setCode(401).setMessage("登录已过期，请重新登录");
    }
    @ExceptionHandler(value = UnauthenticatedException.class)
    public Result handler(UnauthenticatedException e){
        log.error("运行时异常----------------"+e.getMessage());
        return new Result().setCode(401).setMessage("未登录");
    }
}
